package com.itheima.mq.controller;

import com.itheima.mq.config.MyTopic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TestController {

    @Autowired
    private MyTopic topic;

    /**
     * 消息生产接口
     */
    @GetMapping("/sendMessage")
    public String messageWithMQ(@RequestParam String message) {
        log.info("Send: " + message);
        topic.output().send(MessageBuilder.withPayload(message)
                .setHeader("x-delay", 500000).build());
        return "ok";
    }



}
